﻿// Copyright 2005, 2006 - Morten Nielsen (www.iter.dk)
//
// This file is part of SharpMap.
// SharpMap is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// SharpMap is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.

// You should have received a copy of the GNU Lesser General Public License
// along with SharpMap; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 

using System;
using System.Runtime.Serialization;
using System.Collections.Generic;
using System.Text;

namespace Petra.Gis.ReferenceSystemServices
{
  /// <summary>
  /// A 3D coordinate system, with its origin at the center of the Earth.
  /// </summary>
  [DataContract(Name="GEOCCS")]
  [KnownType(typeof(DistanceUnit))]
  public class GeocentricCoordinateSystem : CoordinateSystem
  {

    /// <summary>
    /// xaml constr.
    /// </summary>
    /// <param name="?"></param>
    public GeocentricCoordinateSystem() { }





    public GeocentricCoordinateSystem(HorizontalDatum datum, 
             DistanceUnit storageUnit, 
             PrimeMeridian primeMeridian,
             AxisList axes,
             Metadata metadata)
      : base(storageUnit, axes, metadata)
    {
      HorizontalDatum = datum;
      Unit = storageUnit;
      PrimeMeridian = primeMeridian;
      if (axes.Count != 3)
        throw new ArgumentException("Axis info should contain three axes for geocentric coordinate systems");
    }


    #region GeocentricCoordinateSystem Members

    //private HorizontalDatum _HorizontalDatum;

    /// <summary>
    /// Returns the HorizontalDatum. The horizontal datum is used to determine where
    /// the centre of the Earth is considered to be. All coordinate points will be 
    /// measured from the centre of the Earth, and not the surface.
    /// </summary>
    [DataMember(Name="DATUM", Order = 1)]
    public HorizontalDatum HorizontalDatum
    { get; set; }




    //private PrimeMeridian _Primemeridan;

    /// <summary>
    /// Returns the PrimeMeridian.
    /// </summary>
    [DataMember(Name = "PRIMEM", Order = 2)]
    public PrimeMeridian PrimeMeridian
    { get; set; }




    /// <summary>
    /// Checks whether the values of this instance is equal to the values of another instance.
    /// Only parameters used for coordinate system are used for comparison.
    /// Name, abbreviation, authority, alias and remarks are ignored in the comparison.
    /// </summary>
    /// <param name="obj"></param>
    /// <returns>True if equal</returns>
    public override bool EqualParams(CoordinateSystem obj, CsCompareType compareType)
    {
      if (!(obj is GeocentricCoordinateSystem))
        return false;
      GeocentricCoordinateSystem gcc = obj as GeocentricCoordinateSystem;

      if (!obj.Axes.EqualParams(this.Axes, CsCompareType.CompareAllParams))
        return false;

      if(compareType == CsCompareType.SkipStorageUnits)
        return gcc.HorizontalDatum.EqualParams(this.HorizontalDatum) &&
          gcc.PrimeMeridian.EqualParams(this.PrimeMeridian);
      else
        return gcc.HorizontalDatum.EqualParams(this.HorizontalDatum) &&
          gcc.Unit.EqualParams(this.Unit) &&
          gcc.PrimeMeridian.EqualParams(this.PrimeMeridian);
    }
    #endregion


  }
}
